package com.tmt.paymentcenter.web.configure.security.bean;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;
import org.springframework.stereotype.Component;
import tmt.usercenter.web.domain.security.UserDetailsImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class LogoutHandlerImpl implements LogoutHandler {

    @Autowired
    private TmtClientSessionRegistry sessionRegistry;

    @Override
    public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
        try {
            UserDetailsImpl details = (UserDetailsImpl) authentication.getPrincipal();
            //通知Oauth2服务器，当前用户登出了。
            sessionRegistry.userLogout(details.getUserId(), true);
        }catch (Exception ex){}
    }
}
